﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KCMS.BusinessLogic.Interfaces;
using StructureMap;
using KCMS.BusinessLogic.Models;

namespace KCMS.Areas.Admin.Controllers
{
    [Authorize]
    public class PageCategoryController : Controller
    {
        //
        // GET: /Admin/PageCategory/
        const String imageString = "imageFile";
        private IPageCategoryService pService = ObjectFactory.GetInstance<IPageCategoryService>();
 
        public ActionResult Index()
        {
            var pageCategorys = pService.getAll();
            return View(pageCategorys);
        }
        [HttpGet]
        public ActionResult Create()
        {
           
            var pageCategory = new PageCategory();
            return View(pageCategory);
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Create(PageCategory pageCategory)
        {
            //HttpRequestBase reqvest = this.Request;
            //HttpPostedFileBase image = reqvest.Files[imageString];
         
            pService.save(pageCategory);
            return RedirectToAction("Index");
        }
        [HttpGet]
        public ActionResult Edit(Guid id)
        {
            var model = pService.getById(id);
            return View(model);
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Edit(PageCategory pageCategory)
        {
            //HttpRequestBase reqvest = this.Request;
            //HttpPostedFileBase image = reqvest.Files[imageString];
            pService.update(pageCategory);
            return RedirectToAction("Index");
        }
        [HttpGet]
        public ActionResult Delete(Guid id)
        {
            var model = pService.getById(id);
            return View();
        }
        [HttpPost]
        public ActionResult Delete(PageCategory model)
        {
            pService.delete(model.Id);
            return RedirectToAction("Index");
        }
    }
}
